<?php

session_start();

include_once "src/controller/blmanagement/ResourceManagement.php";
include_once "src/model/User.php";
include_once "src/misc/ClientReponseGenerator.php";

try {

    $resources = ResourceManagement::getAllResources();

    $items = "";
    $resourcesCount = count($resources);
    for ($i = 0; $i < $resourcesCount; $i++) {
        $resource = $resources[$i];
        $items .= "{\"id\":\"".$resource->getResourceId()."\", \"name\":\"".$resource->getResourceName()."\"}";
        if (($resourcesCount > 1) && (($i + 1) < $resourcesCount)) {
            $items .= ",";
        }
    }

    echo ClientReponseGenerator::jsonResponse(1, $items, "", "");

    //DESTROY $_SESSION["resourceIdForReservationCalendar"] IN ORDER TO
    //DISPLAY AN EMPTY RESERVATION CALENDAR WHEN DISPLAYING THE RESERVATION
    //TAB.
    unset($_SESSION["resourceIdForReservationCalendar"]);

} catch (Exception $e) {
    echo ClientReponseGenerator::simpleJsonResponse(0, "GetAllResourcesException", "");
}

?>
